package org.lg.mapper;

import org.apache.ibatis.annotations.*;
import org.lg.entity.Transaction;

import java.util.List;

@Mapper
public interface TransactionMapper {

    // 查询所有交易记录
    @Select("SELECT * FROM transaction_master")
    List<Transaction> getAllTransactions();

    // 根据ID查询交易记录
    @Select("SELECT * FROM transaction_master WHERE id = #{id}")
    Transaction getTransactionById(String id);

    // 添加交易记录
    @Insert("INSERT INTO transaction_master (order_no, item_id, buyer_id, seller_id, transaction_amount, status, reason, created_at, updated_at, transaction_time) " +
            "VALUES (#{orderNo}, #{itemId}, #{buyerId}, #{sellerId}, #{transactionAmount}, #{status}, #{reason}, #{createdAt}, #{updatedAt}, #{transactionTime})")
    void addTransaction(Transaction transaction);

    // 更新交易状态
    @Update("UPDATE transaction_master SET status = #{status}, reason = #{reason}, updated_at = #{updatedAt} WHERE id = #{id}")
    void updateTransactionStatus(Transaction transaction);

    // 删除交易记录
    @Delete("DELETE FROM transaction_master WHERE id = #{id}")
    void deleteTransaction(String id);

    // 获取最后一个订单编号
    @Select("SELECT order_no FROM transaction_master ORDER BY order_no DESC LIMIT 1")
    String getLastOrderNo();
}
